define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'bonus/userbonus/index',
                    add_url: 'bonus/userbonus/add',
                    edit_url: 'bonus/userbonus/edit',
                    del_url: 'bonus/userbonus/del',
                    multi_url: 'bonus/userbonus/multi',
                    table: 'user_bonus',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'bonus_id',
                sortName: 'bonus_id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'bonus_id', title: __('Bonus_id')},
                        {field: 'type.type_name', title: __('Type.type_name')},
                        {field: 'bonus_sn', title: __('Bonus_sn')},
                        {field: 'user_id', title: __('User_id')},
                        // {field: 'used_time', title: __('Used_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'order_id', title: __('Order_id')},
                        {field: 'use_end_date', title: __('Use_end_date'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                queryParams: function (params) {
                  //这里可以追加搜索条件
                  var filter = JSON.parse(params.filter);
                  var op = JSON.parse(params.op);
                  //这里可以动态赋值，比如从URL中获取admin_id的值，filter.admin_id=Fast.api.query('admin_id');
                  filter.bonus_type_id = ids;
                  op.bonus_type_id = "=";
                  params.filter = JSON.stringify(filter);
                  params.op = JSON.stringify(op);
                  return params;
                },
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});